package dcc.component.tabs;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JTable;

import dcc.component.CustomHeader;
import dcc.mbg.model.MProductionAndManagement;
import dcc.mbg.model.MProfessionalSkillService;
import dcc.service.CommonService;
import dcc.tools.BeanFactory;

public class ProfessionalSkillServicePanel extends JPanel implements
		TablePanel.Command {

	private TablePanel<MProfessionalSkillService> tablePanel;

	public ProfessionalSkillServicePanel(CustomHeader... customHeaders) {
		this.tablePanel = new TablePanel<MProfessionalSkillService>(this);
		initLayout();

		String[] headers = new String[] {
				"\u8D77\u59CB\u65F6\u95F4",
				"\u7ED3\u675F\u65F6\u95F4",
				"\u4E13\u4E1A\u6280\u672F\u804C\u52A1(\u6267\u4E1A\u8D44\u683C)",
				"\u8058\u4EFB\u5355\u4F4D\u6216\u8003\u8BC4\u673A\u6784\u540D\u79F0" };
		for (CustomHeader header : customHeaders) {
			headers[header.getIndex()] = (header.getText());
		}

		String[] fields = new String[] { "startDate", "endDate", "job", "unit" };
		List<MProfessionalSkillService> list = new ArrayList<MProfessionalSkillService>();

		tablePanel.setHeader(headers, fields, "id");
		tablePanel.setData(list);
	}

	private void initLayout() {

		GridBagLayout gbl = new GridBagLayout();
		gbl.columnWidths = new int[] { 25, 0, 50, 0 };
		gbl.rowHeights = new int[] { 25, 0, 50, 0 };
		gbl.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
		gbl.rowWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
		this.setLayout(gbl);

		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(0, 0, 5, 5);
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 1;
		gbc_panel.gridy = 1;
		this.add(tablePanel, gbc_panel);
	}

	@Override
	public void deleteRow(int id) {
		((CommonService) BeanFactory.getBean("commonService"))
				.deleteMProfessionalSkillService(id);
	}

	public List<MProfessionalSkillService> getData() {
		return this.tablePanel.getData();
	}

	public void update() {
		this.tablePanel.update();
	}

	@Override
	public Object addRow() {
		return new MProfessionalSkillService();
	}

	@Override
	public void resetWidth(JTable table) {
		table.getColumnModel().getColumn(0).setMaxWidth(120);
		table.getColumnModel().getColumn(0).setMinWidth(120);
		table.getColumnModel().getColumn(1).setMaxWidth(120);
		table.getColumnModel().getColumn(1).setMinWidth(120);
	}
	
	public void setData(List<MProfessionalSkillService> list) {
		tablePanel.setData(list);
	}
}
